<?php
class CMySQL extends MySQL
{
	private $PAGE_NAV_COUNT;
	
//	function __construct()
//	{
//		
//	}
	
	public function Fetch()
	{
		return parent::RowArray(null, MYSQL_ASSOC);
	}
	
	function GetNav()
	{
		global $APPLICATION;
		
		$result = "";

		// Подсчитываем кол-во записей удовлетворяющие результату
		$COUNT = (int) $this->RowCount();
		
		// Определяем номер текущей постраничной навигации
		// При каждой новой постраничной навигации 
		$PAGEN = $this->InitPageNav();
		
		ob_start();
		
		$navComponentObject = CComponent::IncludeComponent(
			"standart:system.pagenavigation",
			"",
			Array(
				"TITLE"=> 'Новости',
				"SHOW_ALWAYS" => 'Y',
				"COUNT" => $COUNT,
				"NAV_VAR" => $PAGEN,
				"PAGE_COUNT" => 9,
				"PAGE_NUMBER" => $_REQUEST[$PAGEN],
				"SHOW_COUNT" => 10,
			)
		);

		$result = ob_get_contents();
		ob_end_clean();

		return $result;
	}
	
	public function InitPageNav()
	{
		!$this->PAGE_NAV_COUNT ? $this->PAGE_NAV_COUNT = 1 : $this->PAGE_NAV_COUNT += 1;
		return 'PAGEN_'.$this->PAGE_NAV_COUNT;
	}
	
	public function GetPageNavCount()
	{
		return $this->PAGE_NAV_COUNT;
	}
	
	public function CreatWhereFilter($arFields = array())
	{
		if(is_array($arFields) && count($arFields))
		{
			$WHERE = ' WHERE ';
			
			foreach ($arFields as $key=>$value)
			{
				$operator = preg_replace("/(\w)?(\d)?(_)?/i", '', $key);
				$operator = strlen($operator) ? $operator : '=';
				
				$key = preg_replace("/[><=!?]?/i", '', $key);
				
				$WHERE .= $key.' '.$operator.' '.CMySQL::SQLValue($value);
				
				//var_dump($operator);
				
			}
			
			return $WHERE;
		}
	}
	
}
?>